﻿// OwnsMineDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "OwnsMine.h"
#include "OwnsMineDlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// COwnsMineDlg 对话框


COwnsMineDlg::COwnsMineDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(COwnsMineDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void COwnsMineDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(COwnsMineDlg, CDialogEx)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_NEWGAME, &COwnsMineDlg::OnBnClickedNewGame)
	ON_BN_CLICKED(IDC_RESET, &COwnsMineDlg::OnBnClickedReset)
	ON_CONTROL_RANGE(BN_CLICKED, BLOCK_ID_MIN, BLOCK_ID_MAX, &COwnsMineDlg::OnBlockLClicked)
	ON_CONTROL_RANGE(WM_RBUTTONUP, BLOCK_ID_MIN, BLOCK_ID_MAX, &COwnsMineDlg::OnBlockRClicked)
	ON_CONTROL_RANGE(WM_LRBUTTONBOTHDCLICKED, BLOCK_ID_MIN, BLOCK_ID_MAX, &COwnsMineDlg::OnBlockLRClicked)
	ON_CONTROL_RANGE(CHECKRDOWN, BLOCK_ID_MIN, BLOCK_ID_MAX, &COwnsMineDlg::ToCheckBlockRDown)
	ON_CONTROL_RANGE(CHECKLDOWN, BLOCK_ID_MIN, BLOCK_ID_MAX, &COwnsMineDlg::ToCheckBlockLDown)
	ON_CONTROL_RANGE(WM_LBUTTONDOWN, BLOCK_ID_MIN, BLOCK_ID_MAX, &COwnsMineDlg::LButtonDown)
	ON_CONTROL_RANGE(WM_LBUTTONUP, BLOCK_ID_MIN, BLOCK_ID_MAX, &COwnsMineDlg::LButtonUp)
	ON_CONTROL_RANGE(WM_LRBUTTONBOTHDOWN, BLOCK_ID_MIN, BLOCK_ID_MAX, &COwnsMineDlg::LRButtonDown)
END_MESSAGE_MAP()


// COwnsMineDlg 消息处理程序

BOOL COwnsMineDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(),GWL_EXSTYLE)^WS_EX_LAYERED);
	SetLayeredWindowAttributes(TRANSPARENT_COLOR , 0, LWA_COLORKEY);
	BOOL bDwm;
	DwmIsCompositionEnabled (&bDwm);
	if (bDwm)
	{ 
		MARGINS mrg = {-1};
		DwmExtendFrameIntoClientArea (m_hWnd , &mrg);
		SetBackgroundColor (TRANSPARENT_COLOR);
		CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
		CMFCButton::EnableWindowsTheming();
	} 
	//目前在这里设定GS的父窗口指针，实际可以修改
	GS.SetCWnd(this);

	// 设置此对话框的图标。当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void COwnsMineDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR COwnsMineDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void COwnsMineDlg::OnBnClickedNewGame()
{
	GS.NewGame();
}

void COwnsMineDlg::OnBlockLClicked(UINT uId)
{
	GS.ButtonEvent( uId, LEFT_CLICK_BLOCK );
}

void COwnsMineDlg::OnBlockRClicked( UINT uId )
{
	GS.ButtonEvent( uId, RIGHT_CLICK_BLOCK );
}

void COwnsMineDlg::OnBlockLRClicked( UINT uId )
{
	GS.ButtonEvent( uId, LEFT_RIGHT_CLICK_BLOCK );
}

void COwnsMineDlg::ToCheckBlockRDown( UINT uId )
{
	GS.ButtonEvent( uId, RIGHT_DOWN_CHECK );
}

void COwnsMineDlg::LButtonDown( UINT uId )
{
	GS.ButtonEvent( uId, LEFT_DOWN );
}

void COwnsMineDlg::LButtonUp( UINT uId )
{
	GS.ButtonEvent( uId, LEFT_UP );
}

void COwnsMineDlg::LRButtonDown( UINT uId )
{
	GS.ButtonEvent( uId, LEFT_RIGHT_DOWN );
}

void COwnsMineDlg::ToCheckBlockLDown( UINT uId )
{
	GS.ButtonEvent( uId, LEFT_DOWN_CHECK );
}

void COwnsMineDlg::OnBnClickedReset()
{
	GS.ReSetGame();
}
